package cc.marcio.systems.seven.process;

import org.apache.log4j.Logger;

import cc.marcio.systems.seven.util.Benchmark;
import cc.marcio.systems.seven.util.ProcessException;


public abstract class BaseProcess implements Runnable {

	private Logger logger = Logger.getLogger(this.getClass());
	
	public abstract void process() throws ProcessException;
	
	protected void sleep(Long time) {
		try {
			if( time == null || time < 0 ) {
				long t = new Double(10000 * Math.random()).longValue();
				Thread.sleep(t);
			} else {
				Thread.sleep(time);
			}
		} catch (InterruptedException e) {
			throw new ProcessException(e);
		}
	}
	
	public void run() {
		Benchmark b = new Benchmark();
		this.logger.debug("############# Starting process " + this.getClass().getSimpleName());
		this.process();
		this.logger.debug("############# Ending process " + this.getClass().getSimpleName() + " -> " + b.getTime());
	}
	
	public void debug(String message) {
		if( this.logger.isDebugEnabled() ) {
			this.logger.debug(message);
		}
	}
}